<template>
  <div class="home">
    <button @click="test">test</button>
    <button @click="queryUser">queryUser</button>
    <button @click="getAllUser">getAllUser</button>
    <button @click="login">login</button>
    <button @click="updateUser">updateUser</button>

    <hr />
    <button @click="queryCustomer">queryCustomer</button>
    <button @click="getAllCustomer">getAllCustomer</button>
    <button @click="addCustomer">addCustomer</button>
    <button @click="updateCustomer">updateCustomer</button>
    <button @click="deleteCustomer">deleteCustomer</button>

    <hr />

    <button @click="queryOrder">queryOrder</button>
    <button @click="getAllOrder">getAllOrder</button>
    <button @click="addOrder">addOrder</button>
    <button @click="updateOrder">updateOrder</button>
    <button @click="deleteOrder">deleteOrder</button>

    <hr />
    {{ msg }}
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: "Home",
  data: function () {
    return {
      msg: "ok",
    };
  },
  components: {},
  methods: {
    test() {
      let data = new Date("2000-12-23");
      data = new Date();
      data = new Date(data.getTime() + 31536000000); //多一年

      data = new Date(data.getTime() + 2628000000); //多一个月
      alert(data);

      // alert("ok");
      // // 接口
      // this.$axios({
      //   url: "/user/test",
      // });
    },

    queryUser() {
      this.$axios({
        url: "/user/queryUser",
        method: "post",
        data: { phone: "222" },
      }).then(function (resp) {
        console.log(resp.data);
      });
    },

    getAllUser() {
      let _this = this;
      this.$axios({
        url: "/user/getAllUser",
        method: "post",
      }).then(function (resp) {
        console.log(resp.data);
        _this.msg = resp.data;
      });
    },

    login() {
      this.$axios({
        url: "/user/login",
        method: "post",
        data: { phone: "222", password: "1121" },
      }).then(function (resp) {
        alert(resp.data == "");
        console.log(resp.data);
      });
    },

    addUser() {
      this.$axios({
        url: "/user/addUser",
        method: "post",
        data: {
          phone: "888",
          password: "111",
          name: "wjh",
          type: "1",
          status: "1",
        },
      }).then(function (resp) {
        alert(resp.data);
        console.log(resp.data);
      });
    },

    updateUser() {
      this.$axios({
        url: "/user/updateUser",
        method: "post",
        data: {
          oldPhone: "888",
          user: {
            phone: "222",
            password: "111",
            name: "w",
            type: "1",
            status: "1",
            id: "4",
          },
        },
      }).then(function (resp) {
        alert(resp.data);
        console.log(resp.data);
      });
    },

    // customer
    queryCustomer() {
      this.$axios({
        url: "/customer/queryCustomer",
        method: "post",
        data: { phone: "222" },
      }).then(function (resp) {
        console.log(resp.data);
      });
    },

    getAllCustomer() {
      this.$axios({
        url: "/customer/getAllCustomer",
        method: "post",
      }).then(function (resp) {
        alert(resp.data);
        console.log(resp.data);
      });
    },

    addCustomer() {
      this.$axios({
        url: "/customer/addCustomer",
        method: "post",
        data: {
          phone: "888",
          name: "wjh",
          orderId: 1,
        },
      }).then(function (resp) {
        alert(resp.data);
        console.log(resp.data);
      });
    },

    updateCustomer() {
      this.$axios({
        url: "/customer/updateCustomer",
        method: "post",
        data: {
          oldPhone: "888",
          customer: {
            phone: "222",
            name: "wjwwsh",
            orderId: 1,
            id: 3,
          },
        },
      }).then(function (resp) {
        alert(resp.data);
        console.log(resp.data);
      });
    },

    deleteCustomer() {
      this.$axios({
        url: "/customer/deleteCustomer",
        method: "post",
        data: { phone: "888" },
      }).then(function (resp) {
        alert(resp.data);
      });
    },

    // order
    queryOrder() {
      this.$axios({
        url: "/order/queryOrder",
        method: "post",
        data: { id: 1 },
      }).then(function (resp) {
        alert(resp.data);
      });
    },

    getAllOrder() {
      this.$axios({
        url: "/order/getAllOrder",
        method: "post",
      }).then(function (resp) {
        alert(resp.data);
      });
    },

    addOrder() {
      this.$axios({
        url: "/order/addOrder",
        method: "post",
        data: {
          serviceId: "1",
          startTime: new Date("2000-12-23"),
          endTime: new Date("2022-12-23"),
          userId: 1,
        },
      }).then(function (resp) {
        alert(resp.data);
      });
    },

    updateOrder() {
      this.$axios({
        url: "/order/updateOrder",
        method: "post",
        data: {
          serviceId: "1",
          startTime: new Date(),
          endTime: new Date("2022-12-23"),
          userId: 1,
          id: 5,
        },
      }).then(function (resp) {
        alert(resp.data);
      });
    },

    deleteOrder() {
      this.$axios({
        url: "/order/deleteOrder",
        method: "post",
        data: { id: 3 },
      }).then(function (resp) {
        alert(resp.data);
      });
    },
  },
};
</script>
